package com.qingrongby.shop.vo;

import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.data.domain.Page;

import javax.swing.*;
import java.util.ArrayList;
import java.util.List;

/**
 * @CLASSNAME PagingDozer
 * @DESCRIPTION TODO
 * @AUTHOR hzp
 * @DATE 2020/6/25
 * @VERSION 1.0
 **/
@Slf4j
@Data
public class PagingDozer<T,k> extends Paging {

    public PagingDozer(Page<T> pageT,Class<k> kClass) {
        this.initPagingFiled(pageT);
        this.copyListItems(pageT,kClass);
    }

    public void copyListItems(Page<T> pageT,Class<k> kClass) {
        List<T> tList=pageT.getContent();
        if(tList.size()<1){
            return;
        }

        List<k> kList= new ArrayList();
        try{
            for(T tObject:tList){
                k kObject= kClass.newInstance();
                BeanUtils.copyProperties(tObject,kObject);
                kList.add(kObject);
            }
        }catch(Exception e){
            log.error("反射出问题");
        }

        this.setItems(kList);
    }

}
